package com.syh.jn.scm.service.impl.downstream.base;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.downstream.entity.base.DownAddress;
import com.syh.jn.scm.domain.downstream.repository.base.DownAddressRepository;
import com.syh.jn.scm.dto.downstream.base.downAddress.DownAddressMto;
import com.syh.jn.scm.dto.downstream.base.downAddress.DownAddressSto;
import com.syh.jn.scm.dto.downstream.base.downAddress.DownAddressVo;
import com.syh.jn.scm.service.api.downstream.base.DownAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 下游地址管理
 */
@Service
@Transactional
public class DownAddressServiceImpl extends AbstractServiceImpl<DownAddressSto, DownAddressMto, DownAddressVo, DownAddress, Long> implements DownAddressService {
  @Autowired
  private DownAddressRepository downAddressRepository;

  @Override
  protected AggregateRepository<DownAddress, Long> getAggregateRepository() {
    return downAddressRepository;
  }

  /**
   * 新增下游地址
   *
   * @param sto
   * @return
   */
  @Override
  public Long save(DownAddressSto sto) {
    DownAddress downAddress = new DownAddress(sto);
    return downAddressRepository.add(downAddress);
  }

  /**
   * 修改下游地址
   *
   * @param mto
   */
  @Override
  public void update(DownAddressMto mto) {
    DownAddress downAddress = downAddressRepository.getById(mto.getId());
    downAddress.modify(mto);
    downAddressRepository.update(downAddress);
  }

  /**
   * 删除下游地址
   *
   * @param id
   */
  @Override
  public void delete(Long id) {
    DownAddress downAddress = downAddressRepository.getById(id);
    downAddressRepository.remove(downAddress);
  }
}
